package com.bjc.nio.c1;

import java.nio.ByteBuffer;

import static com.bjc.nio.util.ByteBufferUtil.debugAll;

/**
 * @program: nettypro
 * @description:
 * @author: bjc
 * @create: 2021-09-15 21:37
 */
public class TestByteBufferRead {

    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(10);
        buffer.put(new byte[]{'a','b','c','d'});
        buffer.flip();

        //rewind  从头开始读
//        buffer.get(new byte[4]);
//        debugAll(buffer);
//        buffer.rewind();
//        debugAll(buffer);
//        System.out.println((char)buffer.get());

        //mark & reset
        //mark 做一个标记 记录position位置 reset是将position重置到mark位置
//        System.out.println((char)buffer.get());
//        System.out.println((char) buffer.get());
//        //加标记 索引2的位置
//        buffer.mark();
//        System.out.println((char)buffer.get());
//        System.out.println((char) buffer.get());
//        //将position重置到索引2
//        buffer.reset();
//        System.out.println((char)buffer.get());
//        System.out.println((char) buffer.get());

        //get(1)  不影响position下标
        System.out.println((char) buffer.get(3));
        debugAll(buffer);
    }
}
